package mysql

import (
	"com-man-sys/comrpc/comrpc"
	"gorm.io/gorm"
)

type Shang struct {
	gorm.Model
	Name    string  `gorm:"type:varchar(30);not null"`
	Price   float32 `gorm:"type:decimal(10,2);not null"`
	Type    int     `gorm:"type:int(11);not null"`
	Address string  `gorm:"type:varchar(30);not null"`
	UserId  int     `gorm:"type:int;not null"`
}

func (s *Shang) ShangAdd(db *gorm.DB) error {
	return db.Create(&s).Error
}

type UserShang struct {
	Sid     int
	Name    string
	Price   float32
	Type    int
	Address string
}

func (s *UserShang) UserFind(db *gorm.DB, list []*comrpc.UserList, in *comrpc.UserListRequest) ([]*comrpc.UserList, error) {
	err2 := db.Debug().Model(&s).Table("shangs").
		Joins("LEFT JOIN users ON users.id = shangs.user_id").
		Where("users.id", in.UserId).
		Find(&list).Error
	return list, err2
}
